package com.key.util;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import com.keyi.core.BaseEntity;

import java.util.HashMap;
import java.util.Map;

public class Config {
    public static void main(String[] args) {
        String basePath = System.getProperty("user.dir");
        String table="Clients";
        String url="jdbc:mysql://10.25.128.144:3307/mao_db";
        String username="root";
        String password="123456";
        FastAutoGenerator.create(url, username, password)
                .globalConfig(builder -> {
                    builder.author("caihua")
                            .disableOpenDir()
                            .enableSwagger()
                            .outputDir(basePath+"/src/main/java");
                })
                .packageConfig(i->{
                    Map<OutputFile,String> pathInfo = new HashMap<>();
                    pathInfo.put(OutputFile.xml,basePath+"/src/main/resources/com/keyi/mapper");
                    i.parent("com.keyi")
                            .pathInfo(pathInfo);;
                }).strategyConfig(i -> {
                    i.addInclude(table);
                    i.entityBuilder()
                            .enableLombok()
                            .superClass(BaseEntity.class)
                            .addSuperEntityColumns("id")
                            .naming(NamingStrategy.underline_to_camel)
                            .columnNaming(NamingStrategy.underline_to_camel)
                            .controllerBuilder()
                            .enableRestStyle()
                            .serviceBuilder()
                            .formatServiceFileName("%sService");

                }).templateEngine(new FreemarkerTemplateEngine())
                .execute();;
    }
}
